﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql  ; 
using System.Data.SqlClient;


using YT.DB;
using YT.Modules;
using YT.Commons;  

namespace YT.XH.SMS
{
   
    public class SMS
    {
        public  bool SendMsg( string strSendMsg, string strSendTo,string strSickName)
        {
            try
            {
                string strConnectionPara = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + DataFunctions.GetApplication() + "\\data.mdb'";
                System.Data.OleDb.OleDbConnection mcon = new System.Data.OleDb.OleDbConnection(strConnectionPara);
                mcon.Open();

                string strSQL = "insert into outbox(Mbno,Msg,username) values( '" + strSendTo + "',  '" + strSendMsg + "','" + strSickName + "' )";
                System.Data.OleDb.OleDbCommand mcomm = new System.Data.OleDb.OleDbCommand(strSQL, mcon);
                mcomm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
            }
            return true;
        }


        public  bool ReadMsg(ref string strReturnMsg )
        {
            
            string strConnectionPara = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='"+ DataFunctions.GetApplication() +"\\data.mdb'";           
            System.Data.OleDb.OleDbConnection mcon = new System.Data.OleDb.OleDbConnection(strConnectionPara);
            mcon.Open();

            string strSQL = "select * from InBox where Readed=0";
            System.Data.OleDb.OleDbCommand sqlCom = new System.Data.OleDb.OleDbCommand(strSQL, mcon);
            System.Data.OleDb.OleDbDataAdapter  sqlAda = new System.Data.OleDb.OleDbDataAdapter(sqlCom);
            System.Data.DataTable dt = new System.Data.DataTable ();
            sqlAda.Fill(dt);
            foreach (System.Data.DataRow drRow in dt.Rows)
            {
                strReturnMsg += "\r\n" + CvtFunc.ToString(drRow["mbno"]) + CvtFunc.ToString(drRow["msg"]);
            }

            mcon.Close();
            return true;
        }

        private bool ClearAllSimMsg(ref string strErrMsg)
        {
     
            return true;
        }
    }
}
